/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Modelo;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.geom.Ellipse2D;
import java.awt.geom.RoundRectangle2D;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author Luigi
 */
public class BotonPersonalisado extends JButton{
    public BotonPersonalisado(){
        //super("Luigiman");
        setContentAreaFilled(false);
        Dimension tamano = getPreferredSize();
        tamano.width = tamano.height = Math.max( tamano.width,tamano.height );
        setPreferredSize( tamano );
       
    }

    //dibuja la figura del boton que se quiere dibujar
    protected  void paintComponent(Graphics g){
       Color p1=new Color(225,225,225);
       Color p2=new Color(235,235,235);
       if(getModel().isArmed()){
           //Cuando se lo tenga presionado
            g.setColor(p1);
       }else{
           //Cuando no se tenga Presionado
            g.setColor(p2);
       }
       //rellena la figura con el color deseado

        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);
       g2.fillOval(0, 0, getSize().width-1, getSize().height-1);
       super.paintComponent(g);
    }




    //pinta la figura que se dibujo
    protected void paintBorder(Graphics g){
        //dibuja el contorno
        g.setColor(getForeground());
        g.drawOval(0, 0, getSize().width-1, getSize().height-1);
    }


    //Verifica si el click se encuentra dentro de la figura
    Shape figura;
    public boolean contains(int x,int y){
        if(figura==null || !figura.getBounds().equals(getBounds())){
        figura = new Ellipse2D.Float(0, 0, getWidth()-1, getHeight()-1);
        }
        return (figura.contains(x,y));
    }

     public static void main(String []args){
        JFrame f=new JFrame();
        f.setSize(200, 200);
        BotonPersonalisado b=new BotonPersonalisado();
       // b.setIcon(new ImageIcon("C:\\Users\\Luigi\\Documents\\NetBeansProjects\\Reproductor(Personalizado)\\src\\Clases\\StepForwardNormalBlue.png"));
      
        JPanel p=new JPanel();
        p.add(b);
        f.add(p);
        f.setVisible(true);
        //b.setVisible(true);
    }


}
